package  com.syqc.sensor.fwdrev

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import autodispose2.autoDispose
import com.syqc.comlib.utils.MLog
import com.syqc.base.BaseReportViewModel
import com.syqc.entity.FwdRev
import com.syqc.net.ServiceHelper

class FwdRevViewModel : BaseReportViewModel() {
    //旋转类型
    private var stateArray = mutableListOf<String>()
    private val _dataLive = MutableLiveData<FwdRev>()
    val dataLive: LiveData<FwdRev> = _dataLive
    var isFwd = true
    var isRev = true
    var isStop = true

    override fun getData(carId: String, startTime: String, endTime: String) {
        stateArray.clear()
        if (isFwd) stateArray.add("\"00\"")
        if (isRev) stateArray.add("\"01\"")
        if (isStop) stateArray.add("\"02\"")
        MLog.e(
            "--------${formatHms(startTime)}---${formatEHms(endTime)}-----${
                stateArray.toString().replace(" ", "")
            }"
        )
        toastLoading(true)
        ServiceHelper.getRepository().getReverse(
            carId,
            formatHms(startTime),
            formatEHms(endTime),
            states = stateArray.toString().replace(" ", "")
        ).autoDispose(this).subscribe({
            toastLoading(false)
            if (isHasListData(it.detail)) return@subscribe
            _dataLive.postValue(it)
        }, error)
    }

    fun formatHms(time: String): String = time.replace(":", "-") + "-00"
    fun formatEHms(time: String): String = time.replace(":", "-") + "-59"
}